# Specify the minimum CMake version required
cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release)
# set(EXECUTABLE_OUTPUT_PATH ../)

# Set the project name
project(image_grayscale)
  
# Set the path to the compiler
set(MXCC_PATH /opt/maca)
set(CMAKE_CXX_COMPILER /opt/maca/mxgpu_llvm/bin/mxcc)

# Set the compiler flags
# set(MXCC_COMPILE_FLAGS -x maca -D AUDIO_ON=1 -I//usr/include/)
set(MXCC_COMPILE_FLAGS -x maca)
add_compile_options(${MXCC_COMPILE_FLAGS})

function(set_target_options target)
    target_include_directories(${target} PRIVATE
            src/lodepng/
            src/
    )

    if (CMAKE_BUILD_TYPE STREQUAL "Debug")
        target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CPP>:-G>)
    else ()
        # needed to get SASS correlation in NCU
        target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CPP>:-lineinfo>)
    endif ()

endfunction()

# Add source files
File(GLOB SRCS src/main.cpp src/lodepng/lodepng.cpp)

# use this for profiling in mcProfiler
add_executable(memory_workload_mode ${SRCS})
set_target_options(memory_workload_mode)
target_compile_options(memory_workload_mode PUBLIC $<$<COMPILE_LANGUAGE:CPP>:--extended-lambda>)
target_compile_options(memory_workload_mode PUBLIC $<$<COMPILE_LANGUAGE:CPP>:--expt-relaxed-constexpr>)
target_link_libraries(memory_workload_mode PRIVATE mcToolsExt)

# use this for simply running the kernels in a benchmark mode
add_executable(memory_workload_benchmark ${SRCS})
set_target_options(memory_workload_benchmark)
target_compile_definitions(memory_workload_benchmark PRIVATE BENCHMARK=1)
target_compile_options(memory_workload_benchmark PUBLIC $<$<COMPILE_LANGUAGE:CPP>:--extended-lambda>)
target_compile_options(memory_workload_benchmark PUBLIC $<$<COMPILE_LANGUAGE:CPP>:--expt-relaxed-constexpr>)
target_link_libraries(memory_workload_benchmark PRIVATE mcToolsExt)